# -*- coding:utf-8 -*-

import tushare as ts

import pandas as pd

pd.set_option('display.max_columns',1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth',1000)

windowSize = 55
# code = "000001"

allStocks = ts.get_stock_basics()['name']
# print(allStocks)

for code, name in allStocks.iteritems():
    dateList = ts.get_k_data(code, start='2019-01-01', ktype='D', autype='qfq')
    dateList.index = dateList.pop("date")
    # print(dateList)
    dateList['hhv'] = dateList['high'].rolling(windowSize).max()
    dateList['pre_hhv'] = dateList['hhv'].shift(1)

    dateList['signals'] = (dateList['close'] > dateList['pre_hhv']) & (dateList['close'].shift(1) <= dateList['pre_hhv'].shift(1))
    # dateList['name'] = allStocks['name']
    result = dateList[dateList['signals']]
    if len(result) > 0:
        print(code, name, list(result.index))

# print(result)
